import com.troyworks.framework.ui.MCButton;
import com.troyworks.ui.menus.Table3DRotaryCarouselMenu;
import com.troyworks.mediaplayer.MixinPlayer;
import com.troyworks.framework.ui.FontManager;
import com.troyworks.ui.menus.CarouselMenu;
import com.troyworks.events.TProxy;
import com.troyworks.framework.ui.BaseComponent;

/**
 * @author Troy Gardner
 */
class com.troyworks.ui.menus.Table3DRotaryCarouselMenuItem  extends BaseComponent {

	public var menu : Table3DRotaryCarouselMenu;
	public var enabled : Boolean = true;
	public var isSelected : Boolean = false;
	public var zoomCount : Number = 0;
	public static var TABLE_CAROUSEL_MODE : Number = 0;
	public static var LINEAR_CAROUSEL_MODE : Number = 1;
	public static var TV_MODE : Number = 1;
	public var mode : Number = TABLE_CAROUSEL_MODE;
	public var data:Object;
	private var zoomme : String;

	private var isToggled : Boolean;

	public var xPos : Number;

	public var yPos : Number;

	public var theScale : Number;
	function Table3DRotaryCarouselMenuItem(aMode : Number) {
		//super(this, this._parent);
		super(null, "Table3DRotaryCarouselMenuItem");
		hsmName = "Table3DRotaryCarouselMenuItem";
		//init();
		this.mode = (aMode == null)?mode:aMode;
	}
	function onLoad() : Void{

		switch(mode){
			case TABLE_CAROUSEL_MODE:
				this.onRollOver =TProxy.create(this, onRollOverHandler1);
				this.onRollOut = TProxy.create(this, onRollOutHandler1);
				this.onRelease = TProxy.create(this, onReleaseHandler1);
				break;
			case LINEAR_CAROUSEL_MODE:
				this.onRollOver =TProxy.create(this, onRollOverHandler2);
				this.onRollOut = TProxy.create(this, onRollOutHandler2);
				this.onRelease = TProxy.create(this, onReleaseHandler2);
				break;
			case TV_MODE:
			break;
		}
		super.onLoad();
	}

	function setEnabled(val : Boolean, bypassRollover : Boolean) : Void{
		trace("111111111111111111111111111111111111111111111");
		trace("111111111111111111111111111111111111111111111");
		trace("111111111111111111111111111111111111111111111");
		trace("1111111111111111111Menu ITem setEnabled " + val + " bypassRollover" + bypassRollover + " 11111111111111111111111111");
		trace("1111111111111111 mode " + mode + " 11111111111111111111111111111");
		trace("111111111111111111111111111111111111111111111");
		enabled = val;
		if(enabled){

			switch(mode){
				case TABLE_CAROUSEL_MODE:
				if(!bypassRollover){
						this.onRollOver =TProxy.create(this, onRollOverHandler1);
						this.onRollOut = TProxy.create(this, onRollOutHandler1);
				}
					this.onRelease = TProxy.create(this, this.onReleaseHandler1);
					break;
				case LINEAR_CAROUSEL_MODE:
					this.onRollOver =TProxy.create(this, onRollOverHandler2);
					this.onRollOut = TProxy.create(this, onRollOutHandler2);
					this.onRelease = TProxy.create(this, onReleaseHandler2);
					break;
				case TV_MODE:
					break;
				
		}		
							
		}else{
			delete onRollOut;
			delete onRollOut;
			delete onRelease;
		}
				
	}
	//////////////////MODE 1 (inside Table Carousel //////////////////
	function onReleaseHandler1() : Void {
		trace("** slide Clicked ***" + util.Trace.me(this.data));
		menu.curSelectedClip = this;
		menu.selectedItem = Object(this).data;
		if(isSelected){
			menu.unReleased();
		}else{
			menu.released();
		}
	}
	function onRollOverHandler1() : Void {
		trace(" ---------OVER------------");
		//BONUS Section
		var sou : Sound = new Sound();
		sou.attachSound("sover");
		sou.start();
		menu.tooltip.tipText.html = true;
		menu.tooltip.tipText.htmlText = Object(this).toolText;
		FontManager.getInstance().styleMe(menu.tooltip, menu.tooltip.tipText);
		menu.activateToolTip(this);
	}
	private function onRollOutHandler1() : Void {
		menu.releaseToolTip();
	}
	///////////////////MODE 2 (inside 1D Carosel /////////////////
	private function onRollOutHandler2() : Void {
		trace("ROLLOUT");
		this.zoomme = "DOWN";
	}
	private function onRollOverHandler2() : Void {
		trace("ROLLOVER");
		this.zoomme = "UP";
		//this._xscale =103;
	}
	private function onReleaseHandler2() : Void {
		trace("*** CLICK *******"+this._parent+" 2 "+this._parent);
		this._parent.enterBook = !this._parent.enterBook;
	//	isToggled = !isToggled;
		if(isToggled){
		//startDrag(false);
		}else{
		//	stopDrag();
		}
		//dispatchEvent("CLICK");
		menu.curSelectedClip = this;
		
		menu.Q_dispatch(CarouselMenu.SELECTED_SLIDE_EVT, this);
	}
	
}